package com.ruoyi.device.controller;

import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.device.domain.DeviceType;
import com.ruoyi.device.service.IDeviceTypeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 设备类别Controller
 * @auth
 * @date
 */
@RestController
@RequestMapping("/device/deviceType")
public class DeviceTypeController extends BaseController {

    @Autowired
    private IDeviceTypeService typeService;

    /**
     * 查询设备分类列表
     */
    @GetMapping("/list")
    public TableDataInfo list(DeviceType params){
        startPage();
        List<DeviceType> list = typeService.getTypeList(params);
        return getDataTable(list);
    }

    /**
     * 获取类别列表，用于下拉列表框
     * @return
     */
    @GetMapping("/getList")
    public AjaxResult getList(){
        return success(typeService.getTypeList(new DeviceType()));
    }

    /**
     * 导出设备分类列表
     */
    @PostMapping("/export")
    public void export(HttpServletResponse response , DeviceType params){
        List<DeviceType> list = typeService.getTypeList(params);
        ExcelUtil<DeviceType> util = new ExcelUtil<>(DeviceType.class);
        util.exportExcel(response, list,"设备分类数据");
    }

    /**
     * 获取设备分类详细信息
     */
    @GetMapping(value = "/getInfo/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id){
        return success(typeService.getTypeById(id));
    }

    /**
     * 新增设备分类
     */
    @PostMapping("/add")
    public AjaxResult add(@RequestBody DeviceType type){
        return toAjax(typeService.addType(type));
    }

    /**
     * 修改设备分类
     */
    @PutMapping("/edit")
    public AjaxResult edit(@RequestBody DeviceType type){
        return toAjax(typeService.editType(type));
    }

    /**
     * 删除设备分类
     */
    @DeleteMapping("/remove/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids){
        return typeService.delTypeByIds(ids);
    }
}
